#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2015-11-02 20:05:56
# @Author  : Kang.cunhua；github：AnInputForce (358608208@qq.com)
# @Link    : https://git.oschina.net/mdr/
# @Version : $Id$

import urllib2
import threading


def download(start):
    req = urllib2.Request('http://www.python.org/')
    req.headers['Range'] = 'bytes=%s-%s' % (start, start+chunk_size)
    f = urllib2.urlopen(req)
    parts[start] = f.read()

threads = []
parts = {}
chunk_size = 1000
# Initialize threads
for i in range(0, 10):
    t = threading.Thread(target=download, args=(i*chunk_size))
    t.start()
    threads.append(t)

# Join threads back (order doesn't matter, you just want them all)
for i in threads:
    i.join()

# Sort parts and you're done
result = ''
for i in range(0, 10):
    result += parts[i*chunk_size]
# SyntaxError: non-keyword arg after keyword arg
# 无名参数要放在关键字参数前面
